{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e9f084e5",
   "metadata": {},
   "source": [
    "-------------------\n",
    "* 日期：2022-10-26 \\ week10\n",
    "* 课程：python\n",
    "* 记录人：Zouyimeng\n",
    "-------------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "c6b8299f",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndentationError",
     "evalue": "unexpected indent (1425955792.py, line 13)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [19]\u001b[1;36m\u001b[0m\n\u001b[1;33m    print()\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m unexpected indent\n"
     ]
    }
   ],
   "source": [
    "# 准备工作\n",
    "product_list = [\n",
    "    [ \"自行车\",299],\n",
    "    [\"Iphone 14 Pro\",8000],\n",
    "    [ \"NFT 盲盒\",28],\n",
    "    [\"许老师的python书\",80]\n",
    "]\n",
    "\n",
    "shopping_car = []\n",
    "\n",
    "# 1.用户输入支付宝余额\n",
    "Alipay = input(\"请输入余额：\")\n",
    "  print()\n",
    "    # 2. 情景1：用户输入了商品编号：shopping\n",
    "user_choice = input(\"请输入商品编号：\") \n",
    "    # 0,1,2,3\n",
    "# 3.在余额足够的情况下 \n",
    "if 钱够, Alipay - 商品价格\n",
    "        shopping_car.append()\n",
    "        else print(\"您的余额已不足，请更换支付方式\")\n",
    " # 4. 情景2：用户输入\"q\",退出购买\n",
    "elif user_choice == \"q\":\n",
    "    print(shopping_car)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "730c95d4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入余额：400\n",
      "----------商品列表----------\n",
      "商品序号 (0)： 自行车 299元\n",
      "商品序号 (1)： Iphone 14 Pro 8000元\n",
      "商品序号 (2)： NFT 盲盒 28元\n",
      "商品序号 (3)： 许老师的python书 80元\n",
      "请输入商品编号：0\n",
      "商品购买成功,您的余额还有101元\n",
      "----------商品列表----------\n",
      "商品序号 (0)： 自行车 299元\n",
      "商品序号 (1)： Iphone 14 Pro 8000元\n",
      "商品序号 (2)： NFT 盲盒 28元\n",
      "商品序号 (3)： 许老师的python书 80元\n",
      "请输入商品编号：a\n",
      "您输入的商品不存在或输入有误，请重新尝试\n",
      "----------商品列表----------\n",
      "商品序号 (0)： 自行车 299元\n",
      "商品序号 (1)： Iphone 14 Pro 8000元\n",
      "商品序号 (2)： NFT 盲盒 28元\n",
      "商品序号 (3)： 许老师的python书 80元\n"
     ]
    }
   ],
   "source": [
    "product_list = [\n",
    "    [ \"自行车\",299],\n",
    "    [\"Iphone 14 Pro\",8000],\n",
    "    [ \"NFT 盲盒\",28],\n",
    "    [\"许老师的python书\",80]\n",
    "]\n",
    "shopping_car = []\n",
    "AliPay = int(input(\"请输入余额：\"))\n",
    "while True:\n",
    "    print(\"----------商品列表----------\")\n",
    "    for i in range(4):\n",
    "        print(\"商品序号\",\"(\"+str(i)+\")：\",product_list[i][0],str(product_list[i][1])+\"元\")  # 格式化输出\n",
    "    # 2. 让用户输入商品编号进行商品的购买。:直接用商品列表的 index 作为商品标号\n",
    "    user_choice = input(\"请输入商品编号：\")\n",
    "    # 情景1：用户正在购买，输入商品编号\n",
    "    if user_choice.isdigit():\n",
    "        # 情景一：余额大于商品价格\n",
    "        if AliPay >= product_list[int(user_choice)][1]:\n",
    "            AliPay = AliPay - product_list[int(user_choice)][1]\n",
    "            shopping_car.append(product_list[int(user_choice)])   \n",
    "            print(\"商品购买成功,您的余额还有%s元\"%(AliPay))\n",
    "        # 情景二：余额小于商品价格\n",
    "        else:\n",
    "            print(\"您的余额不足，请更换支付方式~~~\")\n",
    "    else:\n",
    "        print(\"您输入的商品不存在或输入有误，请重新尝试\")\n",
    "    # 情景2：用户输入退出，结束购买\n",
    "    if user_choice == \"q\":\n",
    "        print(\"您已购买的商品：\",shopping_car)  \n",
    "        print(\"您的余额还有%s,欢迎下次光临~~\"%(AliPay)) \n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9b647113",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "id": "24ad0b0f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入余额：300\n",
      "----------商品列表----------\n",
      "商品序号 (0)： 自行车 299元\n",
      "商品序号 (1)： Iphone 14 Pro 8000元\n",
      "商品序号 (2)： NFT 盲盒 28元\n",
      "商品序号 (3)： 许老师的python书 80元\n",
      "请输入商品编号：0\n",
      "商品购买成功,您的余额还有1元\n",
      "----------商品列表----------\n",
      "商品序号 (0)： 自行车 299元\n",
      "商品序号 (1)： Iphone 14 Pro 8000元\n",
      "商品序号 (2)： NFT 盲盒 28元\n",
      "商品序号 (3)： 许老师的python书 80元\n",
      "请输入商品编号：2\n",
      "您的余额不足，请更换支付方式~~~\n",
      "----------商品列表----------\n",
      "商品序号 (0)： 自行车 299元\n",
      "商品序号 (1)： Iphone 14 Pro 8000元\n",
      "商品序号 (2)： NFT 盲盒 28元\n",
      "商品序号 (3)： 许老师的python书 80元\n",
      "请输入商品编号：q\n",
      "您已购买的商品： [['自行车', 299]]\n",
      "您的余额还有1,欢迎下次光临~~\n"
     ]
    }
   ],
   "source": [
    "product_list = [\n",
    "    [ \"自行车\",299],\n",
    "    [\"Iphone 14 Pro\",8000],\n",
    "    [ \"NFT 盲盒\",28],\n",
    "    [\"许老师的python书\",80]\n",
    "]\n",
    "shopping_car = []\n",
    "AliPay = int(input(\"请输入余额：\"))\n",
    "while True:\n",
    "    print(\"----------商品列表----------\")\n",
    "    for i in range(4):\n",
    "        print(\"商品序号\",\"(\"+str(i)+\")：\",product_list[i][0],str(product_list[i][1])+\"元\")  # 格式化输出\n",
    "    # 2. 让用户输入商品编号进行商品的购买。:直接用商品列表的 index 作为商品标号\n",
    "    user_choice = input(\"请输入商品编号：\")\n",
    "    # 情景1：用户正在购买，输入商品编号\n",
    "    if user_choice.isdigit():\n",
    "        # 情景一：余额大于商品价格\n",
    "        if AliPay >= product_list[int(user_choice)][1]:\n",
    "            AliPay = AliPay - product_list[int(user_choice)][1]\n",
    "            shopping_car.append(product_list[int(user_choice)])   \n",
    "            print(\"商品购买成功,您的余额还有%s元\"%(AliPay))\n",
    "        # 情景二：余额小于商品价格\n",
    "        else:\n",
    "            print(\"您的余额不足，请更换支付方式~~~\")\n",
    "    # 情景2：用户输入退出，结束购买\n",
    "    elif user_choice == \"q\":\n",
    "        print(\"您已购买的商品：\",shopping_car)  \n",
    "        print(\"您的余额还有%s,欢迎下次光临~~\"%(AliPay)) \n",
    "        break"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a066d708",
   "metadata": {},
   "source": [
    "## 购物车模板参考"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "id": "2da0cba5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入余额：30\n",
      "----------商品列表----------\n",
      "商品序号 (0)： 蜜雪柠檬水 6元\n",
      "商品序号 (1)： 蜜桃四季春 10元\n",
      "商品序号 (2)： 芒果奶盖 12元\n",
      "商品序号 (3)： 葡萄波波奶茶 8元\n",
      "请输入商品编号：2\n",
      "商品购买成功，正在制作中...您的余额还有18元\n",
      "----------商品列表----------\n",
      "商品序号 (0)： 蜜雪柠檬水 6元\n",
      "商品序号 (1)： 蜜桃四季春 10元\n",
      "商品序号 (2)： 芒果奶盖 12元\n",
      "商品序号 (3)： 葡萄波波奶茶 8元\n",
      "请输入商品编号：q\n",
      "您已购买的商品： [['芒果奶盖', 12]]\n",
      "您的余额还有18,欢迎下次光临~~\n"
     ]
    }
   ],
   "source": [
    "# 1. 运行程序后，让用户输入支付宝余额 ✔，然后打印我们的商品列表给用户。✔\n",
    "product_list = [\n",
    "    [\"蜜雪柠檬水\",6],\n",
    "    [\"蜜桃四季春\",10],\n",
    "    [\"芒果奶盖\",12],\n",
    "    [\"葡萄波波奶茶\",8]\n",
    "]\n",
    "shopping_car =[]\n",
    "AliPay = int(input(\"请输入余额：\"))\n",
    "while True:\n",
    "    print(\"----------商品列表----------\")\n",
    "    for i in range(4):\n",
    "        print(\"商品序号\",\"(\"+str(i)+\")：\",product_list[i][0],str(product_list[i][1])+\"元\")  # 格式化输出\n",
    "    # 2. 让用户输入商品编号进行商品的购买。:直接用商品列表的 index 作为商品标号\n",
    "    user_choice = input(\"请输入商品编号：\")\n",
    "    # 情景1：用户正在购买，输入商品编号\n",
    "    if user_choice.isdigit():\n",
    "        # 情景一：余额大于商品价格\n",
    "        if AliPay >= product_list[int(user_choice)][1]:\n",
    "            AliPay = AliPay - product_list[int(user_choice)][1]\n",
    "            shopping_car.append(product_list[int(user_choice)])   \n",
    "            print(\"商品购买成功，正在制作中...您的余额还有%s元\"%(AliPay))\n",
    "        # 情景二：余额小于商品价格\n",
    "        else:\n",
    "            print(\"您的余额不足，请更换支付方式~~~\")\n",
    "    # 情景2：用户输入退出，结束购买\n",
    "    elif user_choice == \"q\":\n",
    "        print(\"您已购买的商品：\",shopping_car)  \n",
    "        print(\"您的余额还有%s,欢迎下次光临~~\"%(AliPay)) \n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4ac6d04f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
